package br.gov.cemaden.cliente.inmet;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 *
 * @author alan
 */
public class InmetRejectedExecutionHandler implements RejectedExecutionHandler {

    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        
        Boolean overflow = true;
        
        while(overflow){
            if(executor.getActiveCount() > executor.getMaximumPoolSize()){                
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException ex) {
                }
            }
            else{
                overflow = false;
            }
        }
        executor.execute(r);
    }
    
}
